package com.nengchuan.kbms.dfs.service;

import com.nengchuan.kbms.common.PageServiceImpl;
import com.nengchuan.kbms.dfs.annotation.UserOperateLogger;
import com.nengchuan.kbms.dfs.dao.DataFileInfoMapper;
import com.nengchuan.kbms.dfs.entity.po.DataFileInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文件额外信息表 服务实现类
 * </p>
 *
 * @author abe
 * @since 2020-04-20
 */
@Service
@Slf4j
public class DataFileInfoServiceImpl extends PageServiceImpl<DataFileInfoMapper, DataFileInfo> implements DataFileInfoService {

    @Autowired
    private DataFileInfoMapper dataFileInfoMapper;

    /**
     * 增加文件的下载（预览）次数
     */
    @Override
    public void incrementCount(Long fileId, UserOperateLogger.Type type) {
        try {
            if (UserOperateLogger.Type.DOWNLOAD == type || UserOperateLogger.Type.PREVIEW == type) {
                dataFileInfoMapper.incrementCount(fileId, type.value);
            } else {
                log.warn("暂不支持该操作，当前 type 为：{}", type);
            }
        } catch (Exception e) {
            log.error("increment " + type.value + " count 失败: ", e);
        }
    }

}
